/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "virtual_machine_resources")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "VirtualMachineResources.findAll", query = "SELECT v FROM VirtualMachineResources v"),
    @NamedQuery(name = "VirtualMachineResources.findByIdVMInstance", query = "SELECT v FROM VirtualMachineResources v WHERE v.virtualMachineResourcesPK.idVMInstance = :idVMInstance"),
    @NamedQuery(name = "VirtualMachineResources.findByIdComponent", query = "SELECT v FROM VirtualMachineResources v WHERE v.virtualMachineResourcesPK.idComponent = :idComponent"),
    @NamedQuery(name = "VirtualMachineResources.findByStartTime", query = "SELECT v FROM VirtualMachineResources v WHERE v.startTime = :startTime"),
    @NamedQuery(name = "VirtualMachineResources.findByAllocated", query = "SELECT v FROM VirtualMachineResources v WHERE v.allocated = :allocated")})
public class VirtualMachineResources implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected VirtualMachineResourcesPK virtualMachineResourcesPK;
    @Column(name = "StartTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date startTime;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "Allocated")
    private BigDecimal allocated;
    @JoinColumn(name = "Id_VMInstance", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private VirtualMachineInst virtualMachineInst;
    @JoinColumn(name = "Id_Component", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Component component;

    public VirtualMachineResources() {
    }

    public VirtualMachineResources(VirtualMachineResourcesPK virtualMachineResourcesPK) {
        this.virtualMachineResourcesPK = virtualMachineResourcesPK;
    }

    public VirtualMachineResources(String idVMInstance, String idComponent) {
        this.virtualMachineResourcesPK = new VirtualMachineResourcesPK(idVMInstance, idComponent);
    }

    public VirtualMachineResourcesPK getVirtualMachineResourcesPK() {
        return virtualMachineResourcesPK;
    }

    public void setVirtualMachineResourcesPK(VirtualMachineResourcesPK virtualMachineResourcesPK) {
        this.virtualMachineResourcesPK = virtualMachineResourcesPK;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public BigDecimal getAllocated() {
        return allocated;
    }

    public void setAllocated(BigDecimal allocated) {
        this.allocated = allocated;
    }

    public VirtualMachineInst getVirtualMachineInst() {
        return virtualMachineInst;
    }

    public void setVirtualMachineInst(VirtualMachineInst virtualMachineInst) {
        this.virtualMachineInst = virtualMachineInst;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (virtualMachineResourcesPK != null ? virtualMachineResourcesPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof VirtualMachineResources)) {
            return false;
        }
        VirtualMachineResources other = (VirtualMachineResources) object;
        if ((this.virtualMachineResourcesPK == null && other.virtualMachineResourcesPK != null) || (this.virtualMachineResourcesPK != null && !this.virtualMachineResourcesPK.equals(other.virtualMachineResourcesPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.VirtualMachineResources[ virtualMachineResourcesPK=" + virtualMachineResourcesPK + " ]";
    }
    
}
